package com.douyin_spider.uploadwos;

import com.bj58.spat.wos.ClientConfig;
import com.bj58.spat.wos.WOSClient;
import com.bj58.spat.wos.request.UploadFileRequest;
import com.bj58.spat.wos.sign.Credentials;

public class UploadWos {

    public static String upload (String fileName) {
        String uploadDomain = "";
        //下载资源的域名
        String downDomain = "";
        //获取token的域名
        String tokenserverDomain = "";

        String appId = "";
        String secretId = "";

        String bucket = "";

        ClientConfig clientConfig = new ClientConfig();
        clientConfig.setUploadWosEndPointDomain(uploadDomain);
        clientConfig.setDownWosEndPointDomain(downDomain);
        clientConfig.setTokenServerDomain(tokenserverDomain);
        Credentials cred = new Credentials(appId, secretId);

//		wosclient 1.0.8
//		WOSClient client = new WOSClient(clientConfig, cred);

//		wosclient 1.0.12
        WOSClient client = WOSClient.getWOSClient(clientConfig, cred);
//        String fileName = "weixiao.png";
        String localFilePath = "/Users/a58/backend/emoji_spider/emoji_image/" + fileName;
        UploadFileRequest uploadFileRequest = new UploadFileRequest(bucket, System.currentTimeMillis() + fileName, localFilePath);
        //设置覆盖参数
        //uploadFileRequest.setInsertOnly(InsertOnly.OVER_WRITE);
        String uploadFileRet = client.uploadFile(uploadFileRequest);
        System.out.println("upload file ret:" + uploadFileRet);
        return  uploadFileRet;
    }
}
